﻿#include "ZStageControlDockWidget.h"

ZStageControlDockWidget::ZStageControlDockWidget(QWidget *parent, Qt::WindowFlags flags)
    :QDockWidget(parent, flags)
{
    initContent();
    initConnection();
    setWindowTitle("Stage Control Dialog");
    //setFeatures(QDockWidget::DockWidgetVerticalTitleBar);
}

void ZStageControlDockWidget::setZPosition(double z)
{
    xyPosGB->setZPosition(z);
}


void ZStageControlDockWidget::initContent()
{
    dockWidget = new QWidget(this);
    vLayout = new QVBoxLayout(dockWidget);
    vLayout->setSpacing(6);

    QVBoxLayout *vLayout2 = new QVBoxLayout;

    goHomeGroupBox = new QGroupBox;
    goHomeLayout = new QVBoxLayout(goHomeGroupBox);
    goHomeLayout->setSpacing(6);
    pushButtonGoHomeZ = new QPushButton(goHomeGroupBox);
    pushButtonGoHomeZ->setText("Z GoHome");
    goHomeLayout->addWidget(pushButtonGoHomeZ);
    goHomeLayout->addStretch();
    goHomeGroupBox->setLayout(goHomeLayout);
    goHomeGroupBox->setTitle("GoHome");
    vLayout2->addWidget(goHomeGroupBox);

    xyPosGB = new PositionGroupBox;
    xyPosGB->enableXYPosition(false);
    vLayout2->addWidget(xyPosGB);

    horizontalLayout = new QHBoxLayout;
    horizontalLayout->setSpacing(6);
    zControl = new ZControlGroupBox;
    horizontalLayout->addWidget(zControl);
    horizontalLayout->addLayout(vLayout2);

    vLayout->addLayout(horizontalLayout);
    vLayout->addStretch(10);
    dockWidget->setLayout(vLayout);
    setWidget(dockWidget);

    goHomeGroupBox->setVisible(false);
    xyPosGB->setVisible(false);
}

void ZStageControlDockWidget::initConnection()
{
    connect(zControl, SIGNAL(moveUp(double)), this, SIGNAL(moveUp(double)));
    connect(zControl, SIGNAL(moveDown(double)), this, SIGNAL(moveDown(double)));
    connect(zControl, SIGNAL(moveUpStop()), this, SIGNAL(moveUpStop()));
    connect(zControl, SIGNAL(moveDownStop()), this, SIGNAL(moveDownStop()));
    connect(zControl, SIGNAL(stop()), this, SIGNAL(stopZ()));

    connect(zControl, SIGNAL(changeSpeed(double)), this, SIGNAL(changeZSpeed(double)));
}


void ZStageControlDockWidget::zSpeedUp()
{
    zControl->speedUp();
}

void ZStageControlDockWidget::zSpeedDown()
{
    zControl->speedDown();
}

void ZStageControlDockWidget::joystick_moveUp()
{
    double spd = zControl->speed();
    emit moveUp(spd);
}

void ZStageControlDockWidget::joystick_moveDown()
{
    double spd = zControl->speed();
    emit moveDown(spd);
}

